home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcomm50.zip / LITECOMM.H < prev    next >
Text File  |  1989-02-10  |  7KB  |  259 lines

  1. /*
  2. **    litecomm.h
  3. **        Communications support for Datalight (tm) C
  4. **        Copyright (c) 1987, 1988 - Information Technology, Ltd.,
  5. **                             All Rights Reserved
  6. **  Revisions -
  7. **        01        01/08/88    Modify for DLC 3.21
  8. **                            remove lc_sbrk define
  9. **        2.70    02/25/88    abandon DLC support
  10. **        5.00    02/10/89    change CCB definition for new txready
  11. **                            add define for lc_vport
  12. */
  13.  
  14. #ifndef TRUE
  15. #define TRUE 1
  16. #endif
  17. #ifndef FALSE
  18. #define FALSE 0
  19. #endif
  20. #define ERR (-1)
  21.  
  22. #include <stddef.h>
  23.  
  24. #ifndef LITECOMM_H                /* if not already included        */
  25.  
  26. #define COM1BASE    0x3f8        /* base for com port 1 */
  27. #define COM2BASE    0x2f8        /* base for com port 2 */
  28. #define IRQ1        0x10        /* int req mask for port 1 - irq4 */
  29. #define IRQ2        0x08        /* int req mask for port 2 - irq3 */
  30. #define COM1VEC        0x0c        /* vector for port 1 */
  31. #define COM2VEC        0x0b        /* vector for port 2 */
  32.  
  33. #ifdef KRNL
  34. unsigned COM3BASE = 0x3e8;        /* user changeable com port 3 */
  35. unsigned COM4BASE = 0x2e8;        /* user changeable com port 4 */
  36. char IRQ3 = IRQ1;                /* ditto for int levels */
  37. char IRQ4 = IRQ2;
  38. unsigned COM3VEC = 0x0c;
  39. unsigned COM4VEC = 0x0b;
  40. #else
  41. extern unsigned COM3BASE;
  42. extern unsigned COM4BASE;
  43. extern char IRQ3;
  44. extern char IRQ4;
  45. extern unsigned COM3VEC;
  46. extern unsigned COM4VEC;
  47. #endif
  48.  
  49. /*
  50. **    special control characters
  51. */
  52. #define    XON        0x11
  53. #define    XOFF    0x13
  54.  
  55. /*
  56. **    8250 register defines (offsets from base)
  57. */
  58. #define    THREG    0                /* transmit hold register */
  59. #define RDREG    0                /* input data register */
  60. #define LSBDIV    0                /* least sig. byte of baud rate divisor */
  61. #define MSBDIV    1                /* most sig, only when line ctl bit 7 = 1 */
  62. #define IEREG    1                /* interrupt enable register */
  63. #define IIDREG    2                /* interrupt ID register */
  64. #define LCREG    3                /* line control register */
  65. #define MCREG    4                /* modem control register */
  66. #define LSREG    5                /* line status register */
  67. #define MSREG    6                /* modem status register */
  68.  
  69. /*
  70. **    PARITY SETTINGS used in conjunction with above
  71. */
  72. #define    NPARITY    0x00            /* no parity */
  73. #define OPARITY    0x08            /* odd parity */
  74. #define EPARITY    0x18            /* even parity */
  75. #define    MPARITY    0x28            /* mark parity */
  76. #define SPARITY    0x38            /* space parity */
  77.  
  78. /*
  79. **    DATA and STOP BIT settings
  80. */
  81. #define BIT5    0x00            /* 5 data bits */
  82. #define BIT6    0x01            /* 6 data bits */
  83. #define BIT7    0x02            /* 7 data bits */
  84. #define BIT8    0x03            /* 8 data bits */
  85. #define STOP1    0x00            /* 1 stop bit */
  86. #define STOP2    0x04            /* 2 stop bit */
  87.  
  88. /*
  89. **    Baud Rate Settings
  90. */
  91. #define B110    110
  92. #define    B300    300
  93. #define    B600    600
  94. #define B1200    1200
  95. #define    B2400    2400
  96. #define    B4800    4800
  97. #define    B9600    9600
  98. #define    B19200    19200
  99.  
  100. /*
  101. ** SPECIAL PURPOSE SETTINGS - internal use only
  102. */
  103. #define    BREAK_ON 0x40            /* enable transmitter break */
  104. #define    SETBAUD    0x80            /* enable access to baud rate divisor */
  105.  
  106. #define    DTR        0x01            /* turn on DTR modem signal */
  107. #define RTS        0x02            /* turn on RTS modem signal */
  108. #define    OUT2    0x08            /* enable OUT2 for interrupts */
  109. #define    LOOPBACK 0x10            /* enable loopback mode */
  110.  
  111. #define    RDINT    0x01            /* enable receive data int */
  112. #define    THREINT    0x02            /* enable transmit hold reg empty int */
  113. #define    BRKINT    0x04            /* enable break/error int */
  114. #define    MSTINT    0x08            /* enable modem change int */
  115.  
  116. #define NOPEND    0x01            /* no interrupts pending */
  117. #define INTMST    0x00            /* modem change int */
  118. #define    INTTHRE    0x02            /* THRE int */
  119. #define    INTRD    0x04            /* receive data int */
  120. #define    INTBRK    0x06            /* break/error int */
  121.  
  122. /*
  123. **    line status register values
  124. */
  125. #define    RDRDY    0x01            /* receive data ready */
  126. #define ORUNERR    0x02            /* over-run error */
  127. #define    PARERR    0x04            /* parity error */
  128. #define FRMERR    0x08            /* framing error */
  129. #define    BRKDET    0x10            /* break detect */
  130. #define THREMP    0x20            /* transmit hold reg empty */
  131. #define TSREMP    0x40            /* transmit shift reg empty */
  132. #define TIMEOUT    0x80            /* timeout */
  133.  
  134. /*
  135. **    modem status register values
  136. **        Bits 0 - 3 define which signal(s) have changed
  137. **                   with a value of 1 indicating a change has occurred
  138. **        Bits 4 - 7 indicate the current state of each of the 4 signals
  139. */
  140. #define    CTSCHG    0x01            /* delta CTS */
  141. #define DSRCHG    0x02            /* delta DSR */
  142. #define    RICHG    0x04            /* delta RI */
  143. #define    DCDCHG    0x08            /* delta DCD */
  144. #define    CTS        0x10            /* Clear To Send */
  145. #define DSR        0x20            /* Data Set Ready */
  146. #define RI        0x40            /* Ring Indicator */
  147. #define DCD        0x80            /* Data Carrier Detect */
  148.  
  149. /*
  150. ** macros for litecomm
  151. */
  152.  
  153. /*
  154. ** reduce lc_vport to a macro to speed up code
  155. */
  156.  
  157. #define lc_vport(x) (ports[(x-1)&0x0f])
  158.  
  159. /*
  160. ** defines to resolve differences between MSC and TURBOC
  161. ** semantics
  162. */
  163. #ifdef M_I86
  164. #define IVPTR(x) void (interrupt far *x)()
  165. #define getvect(x) _dos_getvect(x)
  166. #define setvect(x,y) _dos_setvect(x,y)
  167. #define enable _enable
  168. #define disable _disable
  169. #define inportb(x) inp(x)
  170. #define outportb(x,y) outp(x,y)
  171. #define MK_FP(seg,ofs)    ((void far *) \
  172.                (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  173. #endif
  174.  
  175. #ifdef __TURBOC__
  176. #define IVPTR(x) void interrupt (*x)()
  177. #endif
  178.  
  179. #ifdef M_I86
  180. #pragma pack(1)
  181. #endif
  182. typedef    struct
  183. {
  184.     IVPTR(orgvect);             /* original vector */
  185.     unsigned    orgirq;            /* original irq settings */
  186.     unsigned    baseport;        /* baseline port */
  187.     unsigned    pvector;        /* int vector for port */
  188.     unsigned    pirq;            /* port int req mask */
  189.     volatile unsigned mdmstat;    /* current modem status */
  190.     unsigned    mdmctlr;        /* current modem control values */
  191.     volatile unsigned lasterr;    /* last error return */
  192.     volatile unsigned brkrecd;  /* break was detected */
  193.     volatile unsigned txready;    /* TRUE if tranmitter available */
  194.     unsigned    intmask;        /* current active ints */
  195.     char        *inbuff;        /* input ring buffer */
  196.     char        *inbuffend;        /* internal calcs */
  197.     int         inbuflen;        /* size of buffer */
  198.     volatile int inbufcnt;        /* chars in buffer now */
  199.     int            inbufmrk;        /* trigger point for xoff */
  200.     volatile char *inhead;        /* pointer to insert */
  201.     volatile char *intail;        /* pointer to remove */
  202.     int            xstate;            /* TRUE if XON/XOFF active */
  203.     volatile int inxrecd;        /* TRUE if XOFF rec'd */
  204.     volatile int outxsent;        /* TRUE if XOFF sent */
  205.     char        *outbuff;        /* output ring buffer */
  206.     char        *outbuffend;    /* internal calcs */
  207.     int            outbuflen;        /* size of buffer */
  208.     volatile int outbufcnt;        /* chars in buffer now */
  209.     volatile char *outhead;        /* pointer to insert */
  210.     volatile char *outtail;        /* pointer to remove */
  211.     int        rch;        /* port's input char buffer */
  212.     char    far *    oldstk;        /* save area for old stack */
  213.     char    far *    newstk;        /* pointer to handler int stack */
  214.     char    far *    stkbase;    /* pointer to base of int stack */
  215. } COMM;
  216.  
  217. #ifdef M_I86
  218. #pragma pack()
  219. #endif
  220.  
  221. #ifdef KRNL
  222. COMM *ports[16] =    {
  223.                     NULL,NULL,NULL,NULL,
  224.                     NULL,NULL,NULL,NULL,
  225.                     NULL,NULL,NULL,NULL,
  226.                     NULL,NULL,NULL,NULL
  227.                     };
  228. #else
  229. extern COMM *ports[16];
  230. #endif
  231.  
  232. #undef USEHUGE
  233.  
  234. #ifdef M_I86
  235. #ifdef M_I86CM
  236. #define USEHUGE
  237. #endif
  238.  
  239. #ifdef M_I86LM
  240. #define USEHUGE
  241. #endif
  242. #endif
  243.  
  244. #ifdef __TURBOC__
  245. #ifdef __COMPACT__
  246. #define USEHUGE
  247. #endif
  248.  
  249. #ifdef __LARGE__
  250. #define USEHUGE
  251. #endif
  252. #endif
  253.  
  254. #include "litecomm.fns"
  255.  
  256. #define LITECOMM_H    1
  257.  
  258. #endif
  259.